
<template>
    <div class="port-page">
        <!-- 顶部按钮 -->
           <router-link to="/home">
         	<el-button type="info" class="add btn" style='margin-left: 5px;' @click="cancelf" icon="el-icon-caret-left">返回</el-button>
        </router-link>
        <el-button type="info" size="small"  :loading="searchLoading" @click="search" icon="search">搜索</el-button>
        <el-button type="success" size="small" @click='componentsShow("add")' icon="edit">添加</el-button>
        <el-button type="danger" size="small"  :disabled="multipleDeleteDisabled" icon="delete" @click="componentsShow('multipleDelete','')">批量删除</el-button>
        <!-- 模糊搜索条件 -->
        <div class="search">

            <div class="search-item">
                <span>班级名称：</span>
                <el-input placeholder="请输入班级名称" class="code-search" v-model="vkeyword"  @keyup.enter.native="search"></el-input>
            </div>
             <div class="search-item">
                <span>是否启用：</span>
                <el-select v-model="visqy" class="code-search">
                	<el-option label="所有" value=""></el-option>
                    <el-option label="启用" value="Y"></el-option>
                    <el-option label="禁用" value="N"></el-option>
                </el-select>
            </div>
             <div class="search-item">
                <span>时间：</span>
                <!-- <el-input placeholder="请输入开始时间" class="code-search" v-model="vbtime"  @keyup.enter.native="search"></el-input> -->

                <el-date-picker  v-model="vbtime"  type="date" class="code-search" placeholder="选择日期" @keyup.enter.native="search">  </el-date-picker>
                <span>--</span>
                <el-date-picker  v-model="vetime"  type="date" class="code-search" placeholder="选择日期" @keyup.enter.native="search">  </el-date-picker>
       		 </div>
       	</div>
        <!-- 数据表格展示区域 -->
        <el-table
            :data="dataList"
             stripe
             border
            align="left"
            class="admin-table"
            @select="checkSelect"
            @select-all="checkall">
            <el-table-column type="selection" width="55"></el-table-column>
            <div slot='empty'>
                <img src="../../../assets/img/empty.png" style="width:40px;vertical-align: middle;">
                <span style="vertical-align: middle;">暂时还没有内容哦!</span>
            </div>
            <el-table-column
                :prop="v.prop"
                :label="v.label"
                v-for="(v,index) in portTitleList"
                align="center"
                show-overflow-tooltip
                v-if="v.hide != 0"
                :formatter="v.formatter"
                :align="v.align || 'center'"
                :fixed="v.fixed"
                :class-name="v.columnStyle"
                :width="v.width"
                :min-width="v.minWidth"
                :header-align="v.headerAlign || 'center'"
                >
                <template scope="scope">
                    <div slot="reference" :style="tableCellControl(scope)">
                        {{ scope.row[scope.column.property] }}
                    </div>
                 </template>
            </el-table-column>
			         <!-- <el-table-column label="操作" width="160" align="center"> -->
        <el-table-column  fixed="right" align="center"  label="操作"  width="200px">
                <template scope="scope">
                    <!-- v-if="scope.row.qx == 'Y'"-->
                    <router-link to="/educa/check">
                    <el-button size="small" type="text"  @click="componentsShow('kscj',scope)">考试成绩</el-button>
                    </router-link>
                    <el-button size="small" type="text"  @click="componentsShow('sj',scope)">班级升级</el-button>
                    <el-button size="small" type="text"  @click="componentsShow('hls',scope)">换老师</el-button>
                    <router-link to="/educa/workcj">
                    <el-button size="small" type="text"  @click="componentsShow('zyfs',scope)">作业分数</el-button>
                    </router-link>
                    <router-link to="/educa/tingshuozy">
                    <el-button size="small" type="text"  @click="componentsShow('tszy',scope)">听说检查</el-button>
                    </router-link>
                    <el-button size="small" type="text"  @click="componentsShow('fyfx',scope)">发音分析</el-button>
                    <el-button size="small" type="text"  @click="componentsShow('bjtz',scope)">班级通知</el-button>
                    <el-button size="small" type="text"  @click="componentsShow('add',scope)">添加学生</el-button>
                     <router-link to="/educa/tingshuozy">
                    <el-button size="small" type="text"  @click="componentsShow('kq',scope)">考勤</el-button>
                    </router-link>
                    <el-button size="small" type="text"  @click="componentsShow('bjkb',scope)">班级课表</el-button>
                    <el-button size="small" type="text"  @click="componentsShow('bk',scope)">补课</el-button>
                </template>
            </el-table-column>
        </el-table>
        <!-- 分页查询区域 -->
        <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page.sync="pageindex"
            :page-sizes="pagesizes"
            :page-size="pagesize"
            :layout="layout"
            :total="total"
            class="class-page">
        </el-pagination>
        <!-- 各个组件显示区域 -->
        <!-- 动画加载 -->
        <LoadingComponent v-show="isLoading"></LoadingComponent>
        <!-- 添加组件 -->
        <AddComponent v-if="portComponents.add.toggle" @close="componentsHide"></AddComponent>
        <!-- 编辑组件 -->
        <EditComponent v-if="portComponents.edit.toggle" @close="componentsHide" :params="portComponents.edit.params"></EditComponent>
        <!-- info组件 -->
        <infoComponent v-if="portComponents.info.toggle" @close="componentsHide" :params="portComponents.info.params"></infoComponent>
        <!-- 单独删除组件 -->
        <DeleteComponent v-if="portComponents.singleDelete.toggle"  @close="componentsHide"  :data="portComponents.singleDelete.data"></DeleteComponent>
        <!-- 批量删除组件 -->
        <DeleteComponent v-if="portComponents.multipleDelete.toggle"  @close="componentsHide"  :data="portComponents.multipleDelete.data"></DeleteComponent>
        <SjComponent v-if="portComponents.sj.toggle" @close="componentsHide" :params="portComponents.sj.params"></SjComponent>
        <HlsComponent v-if="portComponents.hls.toggle" @close="componentsHide" :params="portComponents.hls.params"></HlsComponent>

        <StudentComponent v-if="portComponents.student.toggle" @close="componentsHide" :params="portComponents.student.params"></StudentComponent>
        <!-- 子路由显示区域 -->
        <router-view class="port-view"></router-view>
    </div>
</template>
<script>
    import { mapState } from 'vuex'
    import LoadingComponent from 'components/loading'
    import AddComponent from './add'
    import EditComponent from './edit'
    import InfoComponent from './info'
    import DeleteComponent from './del'
    import SjComponent from './sj'
    import HlsComponent from './hls'
    import StudentComponent from './student/list'
    export default {
        components: { LoadingComponent, DeleteComponent, AddComponent, EditComponent,InfoComponent,SjComponent,HlsComponent, StudentComponent},
        data () {
            return {

            /*模糊搜索条件*/
               visqy:'',
               vkeyword:'', // keyword
                vbtime:'', // 开始时间
                vetime:'', // 结束时间
				multipleDelNum:'', //获取批量选择的数据
                dataList: [],  //表格数据
                comboxlist:[], //下拉框 动态的
                vcomautovalue:'',//下拉框name 动态的
                vcomgdvalue:'',//下拉框name 固定的

				/*动画加载*/
                isLoading: true,//动画加载
                searchLoading: false,//搜索按钮触发按钮动画
                /*分页属性设置*/
                layout: 'total, sizes, prev, pager, next, jumper',//组件布局
			          pageindex: this.$store.state.pageindex,//当前分页页码
                pagesizes: this.$store.state.pagesizes,//显示个数的选择器选项
                pagesize: this.$store.state.pagesize,//每页显示条目数
                total: 0,//总条数

                /*组件区域*/
                portComponents: {
                    /* 单行删除  */
                    singleDelete: {
                        type: 'singleDelete',
                        toggle: false,
                        params: '',
                        data: {
                            index: '',
                            type: 'single',
                            title: '此操作将删除该记录?, 是否继续?'
                        }
                    },
                    /* 批量删除 */
                    multipleDelete: {
                        type: 'multipleDelete',
                        toggle: false,
                        params: '',
                        data: {
                            index: '',
                            type: 'multiple',
                            title: '此操作将删除您选中的记录?, 是否继续?'
                        }
                    },
                    /* 添加 */
                    add: {
                        type: 'add',
                        toggle: false,
                        params: '',
                        data: {}
                    },
                    /* 编辑 */
                    edit: {
                        type: 'edit',
                        toggle: false,
                        params: '',
                        data: {}
                    },
                    /* info */
                    info: {
                        type: 'info',
                        toggle: false,
                        params: '',
                        data: {}
                    },
                    /* 升级*/
                     sj: {
                        type: 'sj',
                        toggle: false,
                        params: '',
                        data: {}
                    },
                    /* 换老师*/
                     hls: {
                        type: 'hls',
                        toggle: false,
                        params: '',
                        data: {}
                    },
                      /* 班级学生*/
                     student: {
                        type: 'student',
                        toggle: false,
                        params: '',
                        data: {}
                    }

                },
                /*
                    prop :  接口参数名
                    label : 接口中文名
                    hide : 是否隐藏这一列
                    align : 这一列对齐顺序 ： left,right,center
                    headerAlign : 这一列表头对齐方式 ： left,right,center
                */
                portTitleList: [

                    {
                        prop:'id',
                        label:'编号',
                        hide:0,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'mc',
                        label:'班级名称',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'100',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'xzlsmc',
                        label:'行政老师',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'100',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },

                    {
                        prop:'lsmc',
                        label:'老师名称',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'100',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'gh',
                        label:'老师工号',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'100',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },

                    {
                        prop:'dqdymc',
                        label:'当前名称',
                        hide:0,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'120',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'cmc',
                        label:'册名称',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'100',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'jcmc',
                        label:'教材名称',
                        hide:0,
                        align:'center',
                        fixed:false,
                        width:'120',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'xxmc',
                        label:'学校mc',
                        hide:0,
                        align:'center',
                        fixed:false,
                        width:'180',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'isqymc',
                        label:'是否启用',
                        // (班级升级后改为N)
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'100',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'sjqid',
                        label:'升级前id(默认为0)',
                        hide:0,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'lx',
                        label:'创建',
                        // cj/转入zr/转出zc
                        hide:0,
                        align:'center',
                        fixed:false,
                        width:'100',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'sj',
                        label:'创建时间',
                        hide:0,
                        align:'center',
                        fixed:false,
                        width:'170',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'zjmc',
                        label:'助教名称',
                        hide:0,
                        align:'center',
                        fixed:false,
                        width:'100',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'xs',
                        label:'学生人数',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'100',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'ypks',
                        label:'已排课时',
                        hide:0,
                        align:'center',
                        fixed:false,
                        width:'100',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'fxkcmc',
                        label:'分校课程名称',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'130',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'syks',
                        label:'剩余课时',
                        hide:0,
                        align:'center',
                        fixed:false,
                        width:'100',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'kbrq',
                        label:'开班日期',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'170',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    }

                ]
            }
        },
        created () {
            //加载页面时调用
            this.$store.dispatch('changeTitle','教务>班级信息');//修改title
            this.$store.dispatch('changeRouterIndex','/educa/bjxx');//修改路由
            this.search();//分页获取默认数据
            // this.getcomlist(); //加载下拉列表
            this.isLoading = true;//动画开始
            if(this.$route.query.iid){
            if(this.$route.query.frompage == 'xsedit'){
            	this.componentsShow('edit')
            }
            }
        },
        mounted () {
            //加载完成之后event
            this.isLoading = false;//动画结束
        },
        methods: {
//      	tableRowClassName (row, index) {//隔行变色颜色设置
//              // console.log(row)
//              if ( index%4 == 0) {
//                  return "table-cell-red";
//              }else if( index%4 == 1 ){
//                  return "table-cell-yellow";
//              }else if( index%4 == 2 ){
//                  return "table-cell-green";
//              }else{
//                  return "table-cell-blue"
//              }
//          },
cancelf () {
            //sonpage 关闭
          this.$store.dispatch('changeTitle','首页');//修改title
          this.$store.dispatch('changeRouterIndex', '/home');
          // this.params.toggle = false;
            this.$emit('close',{type:'personManage',cancel:true})
          },
          search () {
		    //查询搜索触发事件
	        if(this.vbtime){
	          var time1 = this.$.getLocalTimeNo0(Date.parse(this.vbtime));
	          var time2 = this.$.getLocalTimeNo0(Date.parse(this.vetime));
	        }else{
	          var time1 = this.vbtime
	          var time2 = this.vetime
	        }
            var logininfo = JSON.parse(localStorage.logininfo) ;
              this.searchLoading = true;
              this.axios.get(this.$store.state.api + 'bj/list',{
                  params:{
                      isqy: this.visqy+'',
                      keyword: this.vkeyword+'', // keyword
                      yhid:logininfo.id+'',
                      xxid:logininfo.xxid+'',
                      pageindex: this.pageindex,
                      pagesize: this.pagesize,
                      btime: time1,
                      etime: time2
                  }
              }).then( res => {
                  console.log(res)
                  let data = res.data.data;
                  let list = data.list;
                  this.total = data.totalPage;
                  this.dataList = list;
                  this.searchLoading = false;
              }).catch( res => {
                  console.log(res)
                  this.searchLoading = false;
              })
          },
          getcomlist(){
          /*  var logininfo = JSON.parse(localStorage.logininfo) ;
            this.axios.get(this.$store.state.api + 'dome/list',{
                params:{
                    yhid:logininfo.id,
                    xxid:logininfo.xxid
                }
            }).then( res => {
                console.log(res)
                let data = res.data.data;
                let list = data.list;
                this.total = data.totalPage;
                this.dataList = list;
                this.searchLoading = false;
            }).catch( res => {
            })  */
          } ,
          tableCellControl (scope) {
            //表格单元格控制CSS样式
                /*if (scope.row.id == 112 && scope.column.property == "iname") {
                    return {
                        color:"red",
                    }
                }else{
                    return {
                        color:"green",
                    }
                }*/
           },
           handleSizeChange (val) {//每页显示条数触发事件
                this.pagesize = val;
                this.pageindex = 1;
                this.search();
            },
            handleCurrentChange (val) {//分页触发事件
                this.search();
            },
            checkSelect (selection, row) {//点击单选select触发事件
                console.log(selection, row)
                let strID = [];
                selection.forEach(function(v,i){
                    strID.push(v.id)
                })
                this.multipleDelNum = strID.join(",");
            },
            checkall (selection) {//点击全选select触发事件
                let strID = [];
                selection.forEach(function(v,i){
                    strID.push(v.id)
                })
                this.multipleDelNum = strID.join(",");
            },
            /* 组件的弹框  */
            componentsShow (type,data) { //显示组件
                console.log(type,data)
                for ( let i in this.portComponents ) {
                    if (type == this.portComponents[i].type) {
                        this.portComponents[i].toggle = true;
                        this.portComponents[i].params = data;
                        if (this.portComponents[i].data.type == 'single') {
                            this.portComponents[i].data.index = data.row.id
                        }else if(this.portComponents[i].data.type == 'multiple'){
                            this.portComponents[i].data.index = this.multipleDelNum;
                        }else{
                            return;
                        }
                        return;
                    }
                }
            },
            componentsHide (setting) { //关闭组件
                console.log(setting)
                for ( let i in this.portComponents ) {
                    if (setting.type == this.portComponents[i].type) {
                        this.portComponents[i].toggle = false;
                        if (!setting.cancel) {
                           this.search();
                        }
                        return;
                    }
                }
            }
        },
        computed: {
            ...mapState([
                'api'//域名
            ]),
            multipleDeleteDisabled () {
                console.log(this.multipleDelNum)
                if (this.multipleDelNum) {
                    return false;
                }else{
                    return true
                }
            }
        }
    }
</script>
<style lang="less" scoped>
    .port-page {
        font-size:12px;
        .btn {
            height: 30px;
            padding:0 10px;
        }
        .code-search {
            width: 200px;
            height: 30px;
            margin:10px 0 10px 0;
            min-width: 120px;
            max-width: 150px;
        }
        .change-time{
            width: 480px;
            display: inline-block;
        }
        .class-page {
            text-align: left;
            margin-top:10px;
        }
        .search-item {
            display: inline-block;
            margin-right:10px;
        }
        /*.el-table--enable-row-transition .el-table__body td {
    transition: background-color .25s ease;
    width: 200px;
}*/
    }
</style>
